#include "include/Thread.hpp"
#include <stdio.h>
#include <string.h>

void Thread::join(){
    if(_status == true)
    pthread_join(_pid,nullptr);
    _status = false;
}

void Thread::start(){
    if(_status == false){
      int rep = pthread_create(&_pid,nullptr,start_routine,this);
      if(rep !=0){
          fprintf(stderr,"%s\n",strerror(rep));
      }
      _status = true;
    }
}

bool Thread::isRunning(){
    return _status;
}

void * Thread::start_routine(void * thr){
    Thread * pt = (Thread *)thr;
    if(pt != nullptr){
        pt->run();
    }
    return nullptr;
}






